package com.aqie.easy.doublePointer;

/**
 * 922. 按奇偶排序数组 II
 */
public class SortArrayByParityII {
    public int[] sortArrayByParityII(int[] A) {
        int i = 0, j = 1;
        while(j < A.length && i < A.length){
            // 是偶数
            if (A[i] % 2 == 0){
                i += 2;
            }else{
                while (A[j] % 2 != 0 && j < A.length){
                    j += 2;
                }
                if (j < A.length) {
                    int temp = A[i];
                    A[i] = A[j];
                    A[j] = temp;
                }
            }
        }
        return A;
    }
}
